#!/bin/sh
# Created on 2010-06-02 by Jimmy Wu
# Checks matrix files for zero columns, and prints the filenames
# that have them.
# Output goes to stdout. Use I/O redirection to save the results.

usage () {
    echo "Usage: $(basename $0) matrix_file ..."
}

if [ -z "$1" ] ; then
    usage >&2
    exit 1
fi

status=0

for matrix; do
    if [ "${matrix%-*}" != "$prefix" ] ; then
	# new prefix, read in data
	prefix="${matrix%-*}"
	paramsfile="$prefix".genparam
	if [ -r "$paramsfile" ] && [ -s "$paramsfile" ] ; then
	    read generator segnum params < "$paramsfile"
	else
	    echo "Warning: $paramsfile not found or unreadable." >&2
	    segnum=$( head -n1 "$matrix" | tr -d '[:space:]' | wc -m )
	fi
    fi

    for col in $(seq $segnum) ; do
	if ! cut -d' ' -f $col "$matrix" | grep -q 1  ; then
	    echo "$matrix	$col"
	    status=1
	fi
	col=$(($col + 1))
    done
done

